package com.cloud.lcnpay.entity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
/**
*
*  @author wugy
*/
public class TxPay implements Serializable {

    private static final long serialVersionUID = 1626741958759L;


    /**
    * 主键
    * 主键自增
    * isNullAble:0
    */
    private Integer id;

    /**
    * 支付名称
    * isNullAble:1
    */
    private String payName;


    public void setId(Integer id){this.id = id;}

    public Integer getId(){return this.id;}

    public void setPayName(String payName){this.payName = payName;}

    public String getPayName(){return this.payName;}
    @Override
    public String toString() {
        return "TxPay{" +
                "id='" + id + '\'' +
                "payName='" + payName + '\'' +
            '}';
    }

    public static Builder Build(){return new Builder();}

    public static ConditionBuilder ConditionBuild(){return new ConditionBuilder();}

    public static UpdateBuilder UpdateBuild(){return new UpdateBuilder();}

    public static QueryBuilder QueryBuild(){return new QueryBuilder();}

    public static class UpdateBuilder {

        private TxPay set;

        private ConditionBuilder where;

        public UpdateBuilder set(TxPay set){
            this.set = set;
            return this;
        }

        public TxPay getSet(){
            return this.set;
        }

        public UpdateBuilder where(ConditionBuilder where){
            this.where = where;
            return this;
        }

        public ConditionBuilder getWhere(){
            return this.where;
        }

        public UpdateBuilder build(){
            return this;
        }
    }

    public static class QueryBuilder extends TxPay{
        /**
        * 需要返回的列
        */
        private Map<String,Object> fetchFields;

        public Map<String,Object> getFetchFields(){return this.fetchFields;}

        private List<Integer> idList;

        public List<Integer> getIdList(){return this.idList;}

        private Integer idSt;

        private Integer idEd;

        public Integer getIdSt(){return this.idSt;}

        public Integer getIdEd(){return this.idEd;}

        private List<String> payNameList;

        public List<String> getPayNameList(){return this.payNameList;}


        private List<String> fuzzyPayName;

        public List<String> getFuzzyPayName(){return this.fuzzyPayName;}

        private List<String> rightFuzzyPayName;

        public List<String> getRightFuzzyPayName(){return this.rightFuzzyPayName;}
        private QueryBuilder (){
            this.fetchFields = new HashMap<>();
        }

        public QueryBuilder idBetWeen(Integer idSt,Integer idEd){
            this.idSt = idSt;
            this.idEd = idEd;
            return this;
        }

        public QueryBuilder idGreaterEqThan(Integer idSt){
            this.idSt = idSt;
            return this;
        }
        public QueryBuilder idLessEqThan(Integer idEd){
            this.idEd = idEd;
            return this;
        }


        public QueryBuilder id(Integer id){
            setId(id);
            return this;
        }

        public QueryBuilder idList(Integer ... id){
            this.idList = solveNullList(id);
            return this;
        }

        public QueryBuilder idList(List<Integer> id){
            this.idList = id;
            return this;
        }

        public QueryBuilder fetchId(){
            setFetchFields("fetchFields","id");
            return this;
        }

        public QueryBuilder excludeId(){
            setFetchFields("excludeFields","id");
            return this;
        }

        public QueryBuilder fuzzyPayName (List<String> fuzzyPayName){
            this.fuzzyPayName = fuzzyPayName;
            return this;
        }

        public QueryBuilder fuzzyPayName (String ... fuzzyPayName){
            this.fuzzyPayName = solveNullList(fuzzyPayName);
            return this;
        }

        public QueryBuilder rightFuzzyPayName (List<String> rightFuzzyPayName){
            this.rightFuzzyPayName = rightFuzzyPayName;
            return this;
        }

        public QueryBuilder rightFuzzyPayName (String ... rightFuzzyPayName){
            this.rightFuzzyPayName = solveNullList(rightFuzzyPayName);
            return this;
        }

        public QueryBuilder payName(String payName){
            setPayName(payName);
            return this;
        }

        public QueryBuilder payNameList(String ... payName){
            this.payNameList = solveNullList(payName);
            return this;
        }

        public QueryBuilder payNameList(List<String> payName){
            this.payNameList = payName;
            return this;
        }

        public QueryBuilder fetchPayName(){
            setFetchFields("fetchFields","payName");
            return this;
        }

        public QueryBuilder excludePayName(){
            setFetchFields("excludeFields","payName");
            return this;
        }
        private <T>List<T> solveNullList(T ... objs){
            if (objs != null){
            List<T> list = new ArrayList<>();
                for (T item : objs){
                    if (item != null){
                        list.add(item);
                    }
                }
                return list;
            }
            return null;
        }

        public QueryBuilder fetchAll(){
            this.fetchFields.put("AllFields",true);
            return this;
        }

        public QueryBuilder addField(String ... fields){
            List<String> list = new ArrayList<>();
            if (fields != null){
                for (String field : fields){
                    list.add(field);
                }
            }
            this.fetchFields.put("otherFields",list);
            return this;
        }
        @SuppressWarnings("unchecked")
        private void setFetchFields(String key,String val){
            Map<String,Boolean> fields= (Map<String, Boolean>) this.fetchFields.get(key);
            if (fields == null){
                fields = new HashMap<>();
            }
            fields.put(val,true);
            this.fetchFields.put(key,fields);
        }

        public TxPay build(){return this;}
    }


    public static class ConditionBuilder{
        private List<Integer> idList;

        public List<Integer> getIdList(){return this.idList;}

        private Integer idSt;

        private Integer idEd;

        public Integer getIdSt(){return this.idSt;}

        public Integer getIdEd(){return this.idEd;}

        private List<String> payNameList;

        public List<String> getPayNameList(){return this.payNameList;}


        private List<String> fuzzyPayName;

        public List<String> getFuzzyPayName(){return this.fuzzyPayName;}

        private List<String> rightFuzzyPayName;

        public List<String> getRightFuzzyPayName(){return this.rightFuzzyPayName;}

        public ConditionBuilder idBetWeen(Integer idSt,Integer idEd){
            this.idSt = idSt;
            this.idEd = idEd;
            return this;
        }

        public ConditionBuilder idGreaterEqThan(Integer idSt){
            this.idSt = idSt;
            return this;
        }
        public ConditionBuilder idLessEqThan(Integer idEd){
            this.idEd = idEd;
            return this;
        }


        public ConditionBuilder idList(Integer ... id){
            this.idList = solveNullList(id);
            return this;
        }

        public ConditionBuilder idList(List<Integer> id){
            this.idList = id;
            return this;
        }

        public ConditionBuilder fuzzyPayName (List<String> fuzzyPayName){
            this.fuzzyPayName = fuzzyPayName;
            return this;
        }

        public ConditionBuilder fuzzyPayName (String ... fuzzyPayName){
            this.fuzzyPayName = solveNullList(fuzzyPayName);
            return this;
        }

        public ConditionBuilder rightFuzzyPayName (List<String> rightFuzzyPayName){
            this.rightFuzzyPayName = rightFuzzyPayName;
            return this;
        }

        public ConditionBuilder rightFuzzyPayName (String ... rightFuzzyPayName){
            this.rightFuzzyPayName = solveNullList(rightFuzzyPayName);
            return this;
        }

        public ConditionBuilder payNameList(String ... payName){
            this.payNameList = solveNullList(payName);
            return this;
        }

        public ConditionBuilder payNameList(List<String> payName){
            this.payNameList = payName;
            return this;
        }

        private <T>List<T> solveNullList(T ... objs){
            if (objs != null){
            List<T> list = new ArrayList<>();
                for (T item : objs){
                    if (item != null){
                        list.add(item);
                    }
                }
                return list;
            }
            return null;
        }

        public ConditionBuilder build(){return this;}
    }

    public static class Builder {

        private TxPay obj;

        public Builder(){
            this.obj = new TxPay();
        }

        public Builder id(Integer id){
            this.obj.setId(id);
            return this;
        }
        public Builder payName(String payName){
            this.obj.setPayName(payName);
            return this;
        }
        public TxPay build(){return obj;}
    }

}
